$(function () {
	$("#jqGrid").jqGrid({
		url: baseURL + 'sys/selMonitor',
		datatype: "json",
		colModel: [
			{ label: '监控错误ID', name: 'id', index: "id", width: 45, key: true },
			{ label: '来自系统', name: 'system', index: "system", width: 60 },
			{ label: '请求链接', name: 'href', width: 75 },
			{ label: '错误信息', name: 'errorInfo', index: "error_info", width: 150 },
			{ label: '时间', name: 'time', index: "time", width: 80}
		],
		sortname: "time",
		sortorder: "desc",
		viewrecords: true,
		height: 385,
		rowNum: 10,
		rowList : [10,30,50],
		rownumbers: true,
		rownumWidth: 25,
		autowidth:true,
		multiselect: true,
		pager: "#jqGridPager",
		jsonReader : {
			root: "page.list",
			page: "page.currPage",
			total: "page.totalPage",
			records: "page.totalCount"
		},
		prmNames : {
			page:"page",
			rows:"limit",
			order: "order"
		},
		gridComplete:function(){
			//隐藏grid底部滚动条
			$("#jqGrid").closest(".ui-jqgrid-bdiv").css({ "overflow-x" : "hidden" });
		}
	});
});

let vm = new Vue({
    el: '#monitor',
    data: {
	    showList: true,
	    q:{
		    system: null
	    },
    },
	methods: {
		query: function () {
			vm.reload();
		},
		reload: function () {
			vm.showList = true;
			var page = $("#jqGrid").jqGrid('getGridParam','page');
			$("#jqGrid").jqGrid('setGridParam',{
				postData:{'system': vm.q.system},
				page:page
			}).trigger("reloadGrid");
		},
		del: function () {
			var monitorIds = getSelectedRows();
			if(monitorIds == null){
				return ;
			}

			confirm('确定要删除选中的记录？', function(){
				$.ajax({
					type: "POST",
					url: baseURL + "sys/monitorDel",
					contentType: "application/json",
					data: JSON.stringify(monitorIds),
					success: function(r){
						if(r.code == 0){
							alert('操作成功', function(){
								vm.reload();
							});
						}else{
							alert(r.msg);
						}
					}
				});
			});
		},
	}
});